package lec07datastructure.v1;

public class MyVector {
    int[] data = new int[100];
    int size = 0;


    int get(int x) {
        return data[x];
    }

    void set(int x, int val) {
        data[x] = val;
    }

    void show() {
        for (int i = 0; i < size; i++) {
            System.out.print(data[i] + ",");
        }
        System.out.println();
    }

    void pushBack(int i) {
        if (size == data.length) {
            System.err.println("-----------double capacity-----------------");
            int[] data1 = new int[data.length * 2];
            System.arraycopy(data, 0, data1, 0, data.length);
            data = data1;
        }
        data[size++] = i;
    }

    void popBack() {
        --size;
    }

    public static void main(String[] args) {
        MyVector v = new MyVector();
        for (int i = 0; i < 1000; i++) {
            v.pushBack(i);
            // v.show();
        }
        System.out.println(v.get(0));
        System.out.println(v.get(v.size - 1));
    }
}
